Sh.Parser.Command = new Class({
	initialize : function (cmdLine) {
		this.cmdLine = cmdLine;

		this.parts  = [];
		this.send   = null;
		this.sendTo = null;
		this.next   = null;
		this.pipe   = null;
		this.data   = null;
	},
	setName : function (name) {
		this.name = name;
	},
	addString : function (string) {
		if (this.send) {
			this.sendTo = {
				type : this.send,
				to   : string
			};
			this.send = null;
		} else {
			this.parts.push(string);
		}
		return this;
	},
	ifSuccess : function (nextCmd) {
		this.next = nextCmd;
	},
	pipe : function (cmd) {
		this.pipe = cmd;
	},
	sendResult : function (type) {
		this.send = type;
	},
	setData : function (data) {
		this.data = data;
	},
	run : function () {
		if (this.name in App.Bin) {
			var bin = new App.Bin[this.name](this);
			if (this.data) {
				bin.setData(data);
			}

			bin.onFinish(function (data) {
					if (this.sendTo) {
						new App.Action.Send()
							.type(this.sendTo.type)
							.path(this.sendTo.to)
							.data(data)
							.send();
					} else if (this.pipe) {
						this.pipe.setData(data).run();
					} else if (this.next) {
						this.next.run();
					} else {
						new App.Action.Output()
							.data(data)
							.output();
					}
				}.bind(this))
		} else {
			throw 'Unknown command ' + this.name;
		}
	}
})